package com.hifar.test.api.constant;

/**
 * 员工数据处理错误码枚举
 * 用于标准化员工数据处理错误信息
 */
public enum EmployeeProcessingErrorCode {
    
    // 数据库操作相关错误
    DATABASE_CONNECTION_ERROR("PROC_001", "数据库连接失败", "请检查数据库连接配置"),
    DATABASE_QUERY_ERROR("PROC_002", "数据库查询失败", "请检查查询语句和数据表结构"),
    DATABASE_INSERT_ERROR("PROC_003", "数据库插入失败", "请检查数据完整性和约束条件"),
    DATABASE_UPDATE_ERROR("PROC_004", "数据库更新失败", "请检查更新条件和数据权限"),
    DATABASE_DELETE_ERROR("PROC_005", "数据库删除失败", "请检查删除条件和外键约束"),
    DATABASE_TRANSACTION_ERROR("PROC_006", "数据库事务失败", "请检查事务配置和回滚机制"),
    
    // 数据转换相关错误
    DATA_CONVERSION_ERROR("PROC_007", "数据转换失败", "请检查数据格式和类型转换"),
    BEAN_COPY_ERROR("PROC_008", "对象属性复制失败", "请检查源对象和目标对象的属性映射"),
    DATE_CONVERSION_ERROR("PROC_009", "日期转换失败", "请检查日期格式和时区设置"),
    NUMBER_CONVERSION_ERROR("PROC_010", "数字转换失败", "请检查数字格式和精度设置"),
    
    // 业务逻辑相关错误
    DUPLICATE_USER_CODE("PROC_011", "用户编号重复", "用户编号已存在，请使用不同的编号"),
    INVALID_DEPT_ID("PROC_012", "部门ID无效", "指定的部门不存在或已被删除"),
    USER_NOT_FOUND("PROC_013", "用户不存在", "无法找到指定的用户记录"),
    DEPT_NOT_FOUND("PROC_014", "部门不存在", "无法找到指定的部门记录"),
    BUSINESS_RULE_VIOLATION("PROC_015", "业务规则违反", "数据不符合业务规则要求"),
    
    // 权限相关错误
    ACCESS_DENIED("PROC_016", "访问被拒绝", "当前用户没有执行此操作的权限"),
    DATA_PERMISSION_ERROR("PROC_017", "数据权限错误", "没有访问指定数据的权限"),
    OPERATION_PERMISSION_ERROR("PROC_018", "操作权限错误", "没有执行指定操作的权限"),
    
    // 系统相关错误
    SYSTEM_ERROR("PROC_019", "系统错误", "系统内部发生错误，请稍后重试"),
    MEMORY_ERROR("PROC_020", "内存不足", "系统内存不足，请释放资源后重试"),
    TIMEOUT_ERROR("PROC_021", "处理超时", "数据处理超时，请检查数据量大小"),
    CONCURRENT_ERROR("PROC_022", "并发错误", "数据正在被其他进程处理，请稍后重试"),
    
    // 数据完整性错误
    NULL_POINTER_ERROR("PROC_023", "空指针异常", "数据对象为空，请检查数据完整性"),
    INVALID_DATA_FORMAT("PROC_024", "数据格式无效", "数据格式不符合要求"),
    MISSING_REQUIRED_FIELD("PROC_025", "缺少必填字段", "数据中缺少必填字段"),
    DATA_SIZE_EXCEEDED("PROC_026", "数据大小超限", "数据量超过系统限制"),
    
    // 外部服务相关错误
    EXTERNAL_SERVICE_ERROR("PROC_027", "外部服务错误", "调用外部服务失败"),
    NETWORK_ERROR("PROC_028", "网络错误", "网络连接异常，请检查网络状态"),
    SERVICE_UNAVAILABLE("PROC_029", "服务不可用", "相关服务暂时不可用"),
    
    // 文件操作相关错误
    FILE_READ_ERROR("PROC_030", "文件读取失败", "无法读取指定文件"),
    FILE_WRITE_ERROR("PROC_031", "文件写入失败", "无法写入指定文件"),
    FILE_PERMISSION_ERROR("PROC_032", "文件权限错误", "没有文件操作权限"),
    
    // 配置相关错误
    CONFIG_ERROR("PROC_033", "配置错误", "系统配置不正确"),
    PARAMETER_ERROR("PROC_034", "参数错误", "传入参数不正确"),
    ENVIRONMENT_ERROR("PROC_035", "环境错误", "运行环境配置错误");
    
    private final String code;
    private final String message;
    private final String suggestion;
    
    EmployeeProcessingErrorCode(String code, String message, String suggestion) {
        this.code = code;
        this.message = message;
        this.suggestion = suggestion;
    }
    
    public String getCode() {
        return code;
    }
    
    public String getMessage() {
        return message;
    }
    
    public String getSuggestion() {
        return suggestion;
    }
    
    /**
     * 创建错误响应对象
     */
    public EmployeeProcessingErrorResponse createErrorResponse() {
        return new EmployeeProcessingErrorResponse(this);
    }
    
    /**
     * 员工数据处理错误响应类
     */
    public static class EmployeeProcessingErrorResponse {
        private String code;
        private String message;
        private String suggestion;
        private long timestamp;
        private String operation;
        private String dataId;
        private String stackTrace;
        
        public EmployeeProcessingErrorResponse(EmployeeProcessingErrorCode errorCode) {
            this.code = errorCode.getCode();
            this.message = errorCode.getMessage();
            this.suggestion = errorCode.getSuggestion();
            this.timestamp = System.currentTimeMillis();
        }
        
        public EmployeeProcessingErrorResponse(EmployeeProcessingErrorCode errorCode, String operation, String dataId) {
            this(errorCode);
            this.operation = operation;
            this.dataId = dataId;
        }
        
        // Getters and Setters
        public String getCode() {
            return code;
        }
        
        public void setCode(String code) {
            this.code = code;
        }
        
        public String getMessage() {
            return message;
        }
        
        public void setMessage(String message) {
            this.message = message;
        }
        
        public String getSuggestion() {
            return suggestion;
        }
        
        public void setSuggestion(String suggestion) {
            this.suggestion = suggestion;
        }
        
        public long getTimestamp() {
            return timestamp;
        }
        
        public void setTimestamp(long timestamp) {
            this.timestamp = timestamp;
        }
        
        public String getOperation() {
            return operation;
        }
        
        public void setOperation(String operation) {
            this.operation = operation;
        }
        
        public String getDataId() {
            return dataId;
        }
        
        public void setDataId(String dataId) {
            this.dataId = dataId;
        }
        
        public String getStackTrace() {
            return stackTrace;
        }
        
        public void setStackTrace(String stackTrace) {
            this.stackTrace = stackTrace;
        }
        
        @Override
        public String toString() {
            return "EmployeeProcessingErrorResponse{" +
                    "code='" + code + '\'' +
                    ", message='" + message + '\'' +
                    ", suggestion='" + suggestion + '\'' +
                    ", timestamp=" + timestamp +
                    ", operation='" + operation + '\'' +
                    ", dataId='" + dataId + '\'' +
                    '}';
        }
    }
}
